import express from 'express'
import createApp from '../app'
import { renderToString } from '@vue/server-renderer'

let app = express()
let App = createApp()

// 部署 静态资源
// app.use(express.static("build"));

// 和注册的顺序有关系，优先匹配第一个符合的路径
app.get('/', async (req, res) => {
	const AppContent = await renderToString(App)
	res.send(`
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
      </head>
      <body>
        <h1> Vue + Server Side Render</h1>
        <div id="app">${AppContent}</div>
        <script src="/client/client_bundle.js"></script>
      </body>
    </html>
  `)
})
app.listen(3000, () => {
	console.log('Node Server Start On 3000')
})
